from models import *
from django.shortcuts import render_to_response

def taxons(request):
    tax = Taxon.objects.all()
    return render_to_response("taxons.html", {'taxons': tax})

def taxon(request, id):
    tax = Taxon.objects.get(id=id)
    return render_to_response("taxon.html", {'taxon': tax})
    
def words(request):
    words_ = Word.objects.all()
    return render_to_response("words.html", {'words': words_})
    
def word(request, text):
    wrd = Word.objects.get(word=text)
    return render_to_response("word.html", {'word': wrd})

def meaning(request, id):
    meaning_ = WordMeaning.objects.get(id=id)
    types = list(set([u.usage_type for u in meaning_.usages.all()]))
    return render_to_response("meaning.html", {'meaning': meaning_, 'types': types})

def works(request):
    pass

def works_by_year(request):
    pass

def work_by_code(request, code):
    work = Work.objects.get(code=code)
    return render_to_response('work.html', {'work': work})

def person(request, name):
    person_ = Person.objects.get(name=name)
    return render_to_response('person.html', {'person': person_})

def index(request):
    return words(request)
